<template>
	<view class="out">
		<!-- 单选按钮 -->
		<view class="radio">
			<view>维修方式:</view>
			<uni-data-checkbox v-model="type" :localdata="sex"></uni-data-checkbox>
		</view>
		<!-- 到店维修的页面 -->
		<view v-if="type === 0">
			<view class="gostore">

				<view class="kehuxinxi">
					<!-- 标题 -->
					<view class="title">客户信息</view>
					<!-- 表单 -->
					<view class="input">
						<!-- 车主姓名 -->
						<view class="name">
							<view class="biaoti">车主姓名:</view> <input v-model="name" placeholder="请输入车主姓名" />
						</view>
						<!-- 联系方式 -->
						<view class="name">
							<view class="biaoti">联系方式:</view> <input v-model="phone" placeholder="请输入联系方式" />
						</view>
						<!-- 预约时间 -->
						<view class="name">
							<view class="biaoti">预约时间:</view>
							<input placeholder="请选择时间" @click="open" v-model="reservationTime" />
							<!-- <button >打开时间选择{{ reservationTime }}</button> -->
						</view>

					</view>
				</view>

				<view class="cheliangxinxi">
					<!-- 标题 -->
					<view class="title">车辆信息</view>
					<!-- 表单 -->
					<view class="input">
						<!-- 车主姓名 -->
						<view class="name">
							<view class="biaoti">车辆类型:</view>
							<uni-data-select v-model="carTypeId" :localdata="range" @change="change"></uni-data-select>
						</view>
						<!-- 联系方式 -->
						<view class="name">
							<view class="biaoti2">车牌号:&nbsp;</view> <input v-model="carNum" placeholder="请输入车牌号" />
						</view>


					</view>
				</view>

				<view class="kehuxinxi">
					<!-- 标题 -->
					<view class="title">照片</view>
					<!-- 表单 -->
					<view class="input">
						<!-- 车主姓名 -->
						<view class="name">
							<view class="picture1">整车照片:</view>
							<uni-file-picker :auto-upload="false" v-model="list" @success="success" @fail="fail"
								:image-styles="imageStyles" @select="uploadFile($event,1)"></uni-file-picker>

						</view>
						<!-- 联系方式 -->
						<view class="name">
							<view class="picture2">维修部位照片:</view>
							<uni-file-picker :auto-upload="false" v-model="list1" @success="success" @fail="fail"
								:image-styles="imageStyles" @select="uploadFile($event,2)"></uni-file-picker>
						</view>
					</view>
				</view>
				<button @click="submitFeedback">提交</button>
				<!-- <navigator class="button" url="/pages/carRepair/bookingSuccess/bookingSuccess">
						<button @click="submitFeedback">提交</button></navigator> -->


			</view>
			<zl-delivery-time @change="changeTime" ref="chooseTime" title="请选择预约时间"></zl-delivery-time>
		</view>
		<!-- 上门取车的页面 -->
		<view v-else-if="type === 1">
			<view class="godoor">

				<view class="kehuxinxi">
					<!-- 标题 -->
					<view class="title">客户信息</view>
					<!-- 表单 -->
					<view class="input">
						<!-- 车主姓名 -->
						<view class="name">
							<view class="biaoti">车主姓名:</view> <input v-model="name" placeholder="请输入车主姓名" />
						</view>
						<!-- 联系方式 -->
						<view class="name">
							<view class="biaoti">联系方式:</view> <input v-model="phone" placeholder="请输入联系方式" />
						</view>
						<!-- 预约时间 -->
						<view class="name">
							<view class="biaoti">预约时间:</view>
							<input placeholder="请选择时间" @click="open" v-model="reservationTime" />
							<!-- <button >打开时间选择{{ reservationTime }}</button> -->
						</view>
						<!-- 取车地址 -->
						<view class="name">
							<view class="biaoti">取车位置:</view> <input v-model="location" placeholder="请输入取车位置" />
						</view>
					</view>
				</view>

				<view class="cheliangxinxi">
					<!-- 标题 -->
					<view class="title">车辆信息</view>
					<!-- 表单 -->
					<view class="input">
						<!-- 车主姓名 -->
						<view class="name">
							<view class="biaoti">车辆类型:</view>
							<uni-data-select v-model="carTypeId" :localdata="range" @change="change"></uni-data-select>
						</view>
						<!-- 联系方式 -->
						<view class="name">
							<view class="biaoti2">车牌号:&nbsp;</view> <input v-model="carNum" placeholder="请输入车牌号" />
						</view>


					</view>
				</view>

				<view class="kehuxinxi">
					<!-- 标题 -->
					<view class="title">照片</view>
					<!-- 表单 -->
					<view class="input">
						<!-- 车主姓名 -->
						<view class="name">
							<view class="picture1">整车照片:</view>
							<uni-file-picker :auto-upload="false" v-model="list3" @success="success" @fail="fail"
								:image-styles="imageStyles" @select="uploadFile($event,1)"></uni-file-picker>

						</view>
						<!-- 联系方式 -->
						<view class="name">
							<view class="picture2">维修部位照片:</view>
							<uni-file-picker :auto-upload="false" v-model="list4" @success="success" @fail="fail"
								:image-styles="imageStyles" @select="uploadFile($event,2)"></uni-file-picker>
						</view>
					</view>
				</view>

				<button @click="submitFeedback">提交</button>



			</view>
		</view>

	</view>
</template>
<script>
	export default {
		data() {


			return {
				name: '',
				phone: '',
				carNum: '',
				reservationTime: '',
				vehiclePhotos: '',
				// list: [{
				// 	"name": "file.txt",
				// 	"extname": "img",
				// 	"url": "https://xxxx",
				// }],

				// list1: [{
				// 	"name": "file.txt",
				// 	"extname": "img",
				// 	"url": "https://xxxx",
				// }],
				
				list:[],
				list1:[],
				repairPhotos: '',
				location: '',
				imageStyles: {
					width: 100,
					height: 100,
					border: {
						color: "#dbdbdb",
						width: 2,
						radius: '2px'
					}
				},
				carTypeId: 1,
				range: [{
						value: 1,
						text: "A4"
					},
					{
						value: 2,
						text: "A6"
					},
					{
						value: 3,
						text: "A8"
					},
					{
						value: 4,
						text: "glc"
					},
					{
						value: 5,
						text: "gle"
					},
					{
						value: 6,
						text: "汉"
					},
					{
						value: 7,
						text: "秦"
					},
				],
				type: 0,
				sex: [{
					text: '到店维修',
					value: 0
				}, {
					text: '上门取车',
					value: 1
				}],

			}
		},
		methods: {
			// 选择图片
			uploadFile(e,type) {
				 console.log(e)
				// console.log(e.tempFilePaths)
				this.onUpload(e.tempFilePaths,type)
				
			},
			
			
			
		
			

			// 上传图片
			onUpload(tempFilePaths,type) {
				// 遍历每张图片进行上传
				tempFilePaths.forEach((filePath) => {
					const task = uni.uploadFile({
						url: 'http://localhost:9300/upload', // 这里替换为你的上传接口地址
						filePath: filePath, // 上传的图片路径
						name: 'file',
						success: (resp) => {
							// console.log("上传成功：", resp);
							// console.log(JSON.parse(resp.data))
							var res = JSON.parse(resp.data)
							console.log(type)
							if(type==1){
								this.vehiclePhotos = res.data.url
							}else{
								this.repairPhotos = res.data.url
							}
							// this.list.url = res.data.url
							// this.vehiclePhotos = res.data.url
							//维修部位
							// this.list1.url = res.data.url
							
							// this.repairPhotos = res.data.url
						},
						fail: (err) => {
							console.log("上传失败：", err);
						}
					});
				});
			},
			


			submitFeedback() {
				uni.request({

					url: 'http://localhost:9205/myRepair', // 替换为你的实际接口地址
					method: 'POST',
					header: {
						'authorization': 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6ImI0OWU4NmFkLTZhNTMtNGQyNS1iNzFkLTQ1NjBiOTE2ZTFhNSIsInVzZXJuYW1lIjoiYWRtaW4ifQ.PHw5Ez00yg0Vk_Wx4zO3rnSUHe2znWiWOK2IhwFS80dqK02znBtDbe7GfAiuT3YOQSsnBdIi0O7fjprpExMxlg'
					},
					data: {
						name: this.name,
						phone: this.phone,
						carNum: this.carNum,
						reservationTime: this.reservationTime,
						vehiclePhotos: this.vehiclePhotos,
						repairPhotos: this.repairPhotos,
						type: this.type,
						carTypeId: this.carTypeId,
						location: this.location
					},
					success: (res) => {
						// if (res.data && res.data.id) {
						console.log(res)
						// 获取后端返回的插入数据中的id和orderNumber
						const orderId = res.data.data.id; // 获取新插入数据的 id
						console.log(res.data.data.id)

						// 跳转到预约成功页面，并携带订单id和订单编号
						uni.navigateTo({
							url: `/pages/carRepair/bookingSuccess/bookingSuccess?orderId=${orderId}`
						});
						// } 
						// else {
						//              uni.showToast({
						//                  title: '预约失败',
						//                  icon: 'none'
						//              });
						//          }
					},
					// fail: () => {
					//     uni.showToast({
					//         title: '提交失败，请检查网络',
					//         icon: 'none'
					//     });
					// }
				});
			},


			open() {
				this.$refs.chooseTime.open()
			},
			//选择的时间
			changeTime(e) {
				this.reservationTime = e.value
			},
			change(e) {
				console.log("e:", e);
			},
			// 上传成功
			success(e) {
				console.log('上传成功')
			},

			// 上传失败
			fail(e) {
				console.log('上传失败：', e)
			}



		},
		aa() {
			uni.navigateTo({
				url: ''
			})
		}
	}
</script>
<style lang="scss">
	.out {
		background-color: #ffffff;
		height: 100vh;
		padding: 20rpx 40rpx;
	}

	.radio {
		display: flex;
	}

	.radio>view:nth-child(1) {
		font-weight: 700;
		line-height: 55rpx;
		width: 180rpx;
	}

	.gostore {
		height: 100vh;
		padding-top: 20rpx;
	}

	.godoor {
		height: 100vh;
		padding-top: 20rpx;
	}

	input {
		display: inline-block;
		border: 1rpx solid #cacaca;
		color: #828690;
		font-size: 29rpx;
		height: 56rpx;
		margin-left: 65rpx;
		padding-left: 10rpx;
		width: 400rpx;
	}

	.name {
		display: flex;
		padding: 10rpx 0;
	}

	.input {
		font-size: 29rpx;
	}

	.title {

		font-weight: 700;
		font-size: 31rpx;
		padding-bottom: 10rpx;
	}

	.biaoti {
		line-height: 60rpx;
	}

	.biaoti2 {
		line-height: 60rpx;
		padding-right: 28rpx;
	}

	.picture1 {
		padding-right: 65rpx;
	}

	.picture2 {
		padding-right: 9rpx;
	}

	.button {
		text-align: center;
		margin-top: 60rpx;
	}

	.button>button {

		font-size: 29rpx;
		color: #ffffff;
		background-color: #1d6fff;
		width: 500rpx;
		height: 70rpx;

	}
</style>
<style scoped>
	/deep/.uni-data-checklist .checklist-group .checklist-box[data-v-84d5d996] {
		display: flex;
		flex-direction: row;
		align-items: center;
		position: relative;
		margin: 5px 0;
		margin-right: 37px;
	}

	/deep/.uni-select[data-v-6b64008e] {
		display: inline-block;
		border: 1rpx solid #cacaca;
		color: #828690;
		font-size: 29rpx;
		height: 56rpx;
		margin-left: 65rpx;
		padding-left: 10rpx;
		width: 400rpx;
		box-sizing: inherit;


	}

	/deep/ .uni-select[data-v-6b64008e] {
		color: #000;
	}

	/deep/.uni-select__input-placeholder[data-v-6b64008e] {

		font-size: 29rpx;
	}

	/deep/.uni-select__input-box[data-v-6b64008e] {

		color: #828690;
		line-height: 58rpx;
		align-items: baseline;
		/* align-items: inherit; */
	}

	/deep/[data-v-787f8328] .uni-select[data-v-6b64008e] {
		width: 390rpx;
	}
</style>